how to handle exception in python